var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
//var jwt = require('jsonwebtoken');
var Book = require('./api/models/BookModel');


var port = process.env.PORT || 3000;


mongoose.Promise = global.Promise;
mongoose.connect('mongodb://');

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json()); //加载解析json的中间件


//设置跨域访问
app.all('*', function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By",' 3.2.1')
    res.header("Content-Type", "application/json;charset=utf-8");
    next();
});


// 发送应用程序到路由器
require('./router')(app);

//设置端口号
app.listen(port);

console.log('Listening on: ' + port);

